﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace DoVuiKinhThanh.Domain
{
    /// <summary>
    /// DomainBase
    /// </summary>
    public class DomainBase : INotifyPropertyChanged
    {
        #region IMethods

        public event PropertyChangedEventHandler PropertyChanged;

        // Create the OnPropertyChanged method to raise the event 
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        protected void OnPropertyChanged<T>(Expression<Func<T>> expression)
        {
            OnPropertyChanged(GetPropertyName(expression));
        }

        protected string GetPropertyName<T>(Expression<Func<T>> propertyExpression)
        {
            return (propertyExpression.Body as MemberExpression).Member.Name;
        }

        #endregion

        #region IProperties

        /// <summary>
        /// Gets or sets the identifier.
        /// </summary>
        /// <value>
        /// The identifier.
        /// </value>
        public int Id
        {
            get;
            set;
        }

        #endregion
    }
}